newline = {"\n"}

ab_ending_on_a = {
  "ab"* ~ "a"
}

ab_ending_on_b = {
  "ab"+
}

ba_ending_on_b = {
  "ba"* ~ "b"
}

ba_ending_on_a = {
  "ba"+
}

ab_combination = {
    ab_ending_on_a | ab_ending_on_b
}

ba_combination = {
    ba_ending_on_b | ba_ending_on_a
}

combination = {
    SOI ~
    (ab_combination | ba_combination) ~
    newline? ~
    EOI
}